<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${category == null ? '创建' : '编辑'}分类</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
</head>
<body>
<!--头部-->
<div class="index-outside">
    <!--内容-->
    <section class="no-fix">
        <div class="section-main" style="min-width: 10px">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/photo/album/third/save.do">
                    <input type="hidden" name="id" value="${photosTag.id}"/>
                    <input type="hidden" name="photosId" value="${photosTag.photosId}"/>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类名称<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="name" autocomplete="off" style="width: 200px"
                                   placeholder="请输入分类名称" class="layui-input" value="${photosTag.name}"
                            >
                            <div class="layui-form-mid layui-word-aux" style="">最多5个汉字或10个字母(数字)</div>
                        </div>
                    </div>
                </form>
            </div>
        </div><!--底部-->
    </section>
</div>
<script>
    function ajaxSubmit(data, url, cb) {
        $.ajax({
            type: 'POST',
            async: false, // 使用同步的方法
            data: data,
            dataType: 'json',
            success: function (result) {
                typeof cb === 'function' && cb(result);
            },
            url: url
        });
    }

    function verify() {
        var name = $("[name=name]").val();
        if (!util.isValid(name)) {
            util.layerMsgError("分类名称不能为空")
            return false;
        }
        if (util.strRealLength(name) > 10) {
            util.layerMsgError("分类名称不能超过5个特殊字符或10个字母/数字")
            return false;
        }
        return true;
    }

    function doSubmit() {
        var flag = false;
        if (verify()) {
            ajaxSubmit($('#myForm').serialize(), $("#myForm").attr('action'), function (res) {
                flag = res.success;
                if (res.success) {
                    util.layerMsgSuccess("提交成功")
                } else {
                    util.layerMsgError(res.description)
                }
            });
        }
        return flag;
    }

</script>
</body>
</html>